﻿<%
Class Ashapo_Err_Class

	'是否启用调试
	Private s_debug
	'最后错误代码
	Private s_lastErrNum
	'错误页面标题,错误页面信息
	Private s_title, s_msg
	'错误信息字典,错误字典的分配问题
	'000-099分配给系统错误，采取语言包定义增强性能
	'000特殊,预留
	'001-020-fso
	'021-030-asp
	'031-070-tpl
	Private s_errDict
	'错误收集器
	Public Collector

	'''构造
	Private Sub Class_Initialize()
		'表示无错误/未知错误
		s_lastErrNum = ""
		If Not G_Debug = "" Then
			s_debug = G_Debug
		Else
			s_debug = C_Debug
		End If
		s_title = L_str_500_ttl
		s_msg = L_str_500_msg
		Set s_errDict = Server.CreateObject(C_DicName)
		Set Collector = Server.CreateObject(C_DicName)
	End Sub
	
	'''析构
	Private Sub Class_Terminate()
		Set s_errDict = Nothing
		Set Collector = Nothing
	End Sub
	
	'''查看是否启用开发者调试环境
	Public Property Get [Debug]
		[Debug] = s_debug
	End Property
	
	'''设置是否启用开发者调试环境
	Public Property Let [Debug](Byval p_b)
		s_debug = p_b
	End Property
	
	'''获取错误页面标题
	'仅对于500错误有效,404错误由语言包决定
	Public Property Get Title()
		Title = s_title
	End Property
	
	'''设置错误页面标题
	'仅对于500错误有效,404错误由语言包决定
	Public Property Let Title(ByVal p_s)
		s_title = p_s
	End Property
	
	'''获取错误页面提示信息
	'仅对于500错误有效,404错误由语言包决定
	Public Property Get Msg()
		Msg = s_msg
	End Property
	
	'''设置错误页面提示信息
	'仅对于500错误有效,404错误由语言包决定
	Public Property Let Msg(ByVal p_s)
		s_msg = p_s
	End Property
	
	'''格式化错误代号,如将0转化为000，10转化为010
	Private Function formatErrNum_(Byval p_n)
		If isNumeric(p_n) Then
			p_n = Cint(p_n)
			If p_n < 10 Then
				formatErrNum_ = "00" & Cstr(p_n)
			ElseIf p_n < 100 Then
				formatErrNum_ = "0" & Cstr(p_n)
			Else
				formatErrNum_ = Cstr(p_n)
			End If
		Else
			formatErrNum_ = p_n
		End If
	End Function
	
	'''获取错误字典信息,默认使用
	Public Default Property Get E(Byval p_n)
		'000-099直接语言包返回错误定义
		If isNumeric(p_n) Then
			If Cint(p_n) < 100 Then
				E = Eval("Cstr(L_str_err_"&formatErrNum_(p_n)&")")
				Exit Property
			End If
		End If
		'常规情况使用错误字典
		If s_errDict.Exists(p_n) Then
			E = s_errDict(p_n)
		Else
			E = "Unknown Error"
		End If
	End Property
	
	'''设置错误信息字典
	Public Property Let E(Byval p_n, Byval p_s)
		'禁止修改底层错误信息
		If isNumeric(p_n) Then
			If Cint(p_n) < 100 Then
				Exit Property
			End If
		End If
		If Has(p_n) And Has(p_s) Then
			If p_n > "" Then
				s_errDict(formatErrNum_(p_n)) = p_s
			End If
		End If
	End Property
	
	'''获取最后一个错误代码
	Public Property Get LastError()
		LastError = s_lastErrNum
	End Property
	
	'''根据错误代码收集错误
	Public Sub Raise(Byval p_n)
		If IsN(p_n) Then Exit Sub
		s_lastErrNum = p_n
		Collector(formatErrNum_(p_n)) = E(p_n)
	End Sub
	
	'''输出已定义的错误字典
	Public Sub Defined()
		Dim t_key
		If Has(s_errDict) Then
			For Each t_key In s_errDict
				Response.Write(t_key & " : " & s_errDict(t_key) & "<br />" & VbCrLf)
			Next
		End If
	End Sub
	
	'''直接抛出错误信息
	'传入数字则根据错误收集器id
	'传入字符串则直接显示该错误信息
	'如果传入的是语言自定义包则可以支持多语
	Public Sub [Throw](Byval p_msg)
		If isNumeric(p_msg) Then
			Call Sa.Go500(Cint(p_msg), "", "")
		Else
			Call Sa.Go500("", "", p_msg)
		End If
	End Sub
End Class
%>